package com.example.shirodemo.controller;

import cn.hutool.crypto.digest.MD5;
import com.example.shirodemo.config.RedisConfig;
import com.example.shirodemo.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    RedisService redisService;

    @RequestMapping("/login/{username}/{password}")
    public Object login(@PathVariable String username,@PathVariable String password){

        if("admin".equals(username)&&"123".equals(password)){
            //生成token
            // 使用Hutool的MD5工具类生成MD5摘要
            String token = MD5.create().digestHex(username+password);
            //保存到redis
            redisService.saveTtl(RedisConfig.PREFIX_USER_TOKEN+token,token,RedisConfig.REDIS_TOKEN_TIME);
            return "登录成功；token:"+token;
        }else{
            //登录失败
            return "login err";
        }
    }

    @RequestMapping("/sysUser")
    public Object logina(){
        return "sysUser";
    }



    public String getToken(String username,String password){
        return "";
    }


}
